<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:fn="http://java.sun.com/jsp/jstl/functions"
                xmlns:f="http://java.sun.com/jsf/core">
    <h:form id="emp"> 
        <rich:panel header="生成资产" styleClass="content-hight">
            <rich:messages/>
            <rich:toolbar>
                <rich:toolbarGroup id="tolbar">
                    <a4j:commandButton value="生成资产"
                                       action="#{buildAssetBean.queryExecli}"
                                       execute="@this"
                                       render="assetGroup"
                                       onclick="#{rich:component('assetPanel')}.show();"/>
                    <a4j:commandButton value="保存"  action="#{buildAssetBean.save}" render="saveGroup"/>
                </rich:toolbarGroup>
            </rich:toolbar>

            <h:panelGroup id="saveGroup">
                <h:selectOneMenu value="#{buildAssetBean.updateLabel}"
                                 disabled="#{empty buildAssetBean.saveli}">
                    <f:selectItem itemLabel="-选择修改字段-" itemValue=""/>
                    <f:selectItem itemLabel="资产名称" itemValue="name"/>
                    <f:selectItem itemLabel="规格型号" itemValue="model"/>
                    <f:selectItem itemLabel="单价" itemValue="price"/>
                    <f:selectItem itemLabel="品牌" itemValue="brand"/>
                    <f:selectItem itemLabel="厂商" itemValue="manufacture"/>
                    <f:ajax render="updateValueId"/>
                </h:selectOneMenu>
                <h:inputText id="updateValueId"
                             value="#{buildAssetBean.updateValue}"
                             disabled="#{empty buildAssetBean.saveli}">
                    <a4j:ajax event="blur" render="saveGroup" listener="#{buildAssetBean.updateProperty}"/>
                </h:inputText>
                <br/>
                <h:panelGroup id="tableGroup">
                    <rich:dataScroller for="saveTable" execute="@this" render="tableGroup"/>
                    <div style="width:780px;overflow:auto;">
                        <rich:dataTable id="saveTable"
                                        value="#{buildAssetBean.saveli}" var="asset"
                                        rowClasses="list-row-odd,list-row-even"
                                        headerClass="table-header"
                                        style="width:1200px;margin-bottom: 20px;"
                                        noDataLabel="无数据！"
                                        rowKeyVar="rowKey"
                                        rows="10">
                            <rich:column style="text-align: center">
                                <h:selectBooleanCheckbox value="#{asset.selected}">
                                    <f:ajax event="click"/>
                                </h:selectBooleanCheckbox>
                            </rich:column>
                            <rich:column style="text-align: center">
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="序号"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:outputText  value="#{rowKey+1}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="资产编号"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:outputText  value="#{asset.assetCode}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="资产名称"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:inputText value="#{asset.assetName}" />
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="国标编码及名称"/>
                                    </h:panelGroup>
                                </f:facet>
                                <a4j:commandLink onclick="#{rich:component('GBCodePlan')}.show();"
                                                 execute="@this" render="EditGBCode">
                                    <a4j:param value="#{rowKey}" assignTo="#{buildAssetBean.rowIndex}"/>
                                    <h:outputText value="[#{asset.classCode}][#{asset.className}]" />
                                </a4j:commandLink>
                            </rich:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="规格型号"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:inputText value="#{asset.model}"/>
                            </h:column>
                            <h:column rendered="false">
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="部门名称"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:outputText value="#{asset.dept.name}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="使用人"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:outputText value="#{asset.person.cpsn_name}"/>
                            </h:column>

                            <h:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="单价"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:inputText value="#{asset.price}">                            
                                    <f:convertNumber type="double" pattern="#,##0.00"/>
                                </h:inputText>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="品牌"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:inputText value="#{asset.brand}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="厂商"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:inputText value="#{asset.manufacture}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="购置日期"/>
                                    </h:panelGroup> 
                                </f:facet>
                                <rich:calendar 
                                    value="#{asset.purchDate}"
                                    locale="zh_CN"
                                    popup="true"
                                    datePattern="yyyy-MM-dd"
                                    showApplyButton="true"
                                    style="width:200px"/>
                            </h:column>
                            <h:column rendered="false">
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="质保日期"/>
                                    </h:panelGroup> 
                                </f:facet>
                                <rich:calendar 
                                    value="#{asset.shelfLife}"
                                    locale="zh_CN"
                                    popup="true"
                                    datePattern="yyyy-MM-dd"
                                    showApplyButton="true"
                                    style="width:200px"/> 
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="使用状况"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:outputText value="在用"  rendered="#{asset.useStatus == '0'}"/>
                                <h:outputText value="报废"  rendered="#{asset.useStatus == '1'}" style="color:blue;"/>
                                <h:outputText value="报损"  rendered="#{asset.useStatus == '2'}" style="color:red;"/>
                                <h:outputText value="其他"  rendered="#{asset.useStatus == '3'}" style="color:ccddff;"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:panelGroup style="white-space: nowrap;">
                                        <h:outputText value="备注"/>
                                    </h:panelGroup>
                                </f:facet>
                                <h:inputText value="#{asset.memo}"/>
                            </h:column>
                        </rich:dataTable>
                    </div>
                </h:panelGroup>
            </h:panelGroup>
        </rich:panel>
    </h:form>
    <rich:popupPanel id="assetPanel" autosized="true" width="850">
        <f:facet name="header">采购信息</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('assetPanel')}.hide();
                                               return false;">
                关闭
            </h:outputLink>
        </f:facet>
        <h:form>
            <rich:panel>
                <h:panelGroup id="assetGroup">
                    <a4j:commandButton value="确定" action="#{buildAssetBean.buildAsset}"
                                       oncomplete="#{rich:component('assetPanel')}.hide();"
                                       render="saveGroup"/>
                    <a4j:commandButton value="取消" onclick="#{rich:component('assetPanel')}.hide();"/>
                    <hr/>
                    <div style="width:780px;min-height: 300px;overflow:auto;">
                        <rich:dataTable id="editTable1"
                                        value="#{buildAssetBean.execModel}" var="emp"
                                        rowKeyVar="rowKey"
                                        noDataLabel="无数据!"
                                        style="width:1200px;">

                            <rich:column style="text-align: center;width:30px;">
                                <h:selectBooleanCheckbox value="#{emp.selected}">
                                    <a4j:ajax event="click" render="@this" execute="@this" />
                                </h:selectBooleanCheckbox>
                            </rich:column>
                            <rich:column style="text-align: center;width:30px;">
                                <f:facet name="header">序号</f:facet>
                                    #{rowKey+1}
                            </rich:column>
                            <rich:column style="text-align:center;">
                                <f:facet name="header">资产信息</f:facet>
                                <a4j:commandLink value="【编辑】" action="#{buildAssetBean.addExeAppend}"
                                                 onclick="#{rich:component('appendPanel')}.show();"
                                                 render="editGridAppend"
                                                 style="text-decoration: none;"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">类别</f:facet>
                                <h:outputText value="#{emp.planWay}"/>
                            </rich:column>
                            <rich:column >
                                <f:facet name="header">基本/项目</f:facet>
                                <h:outputText value="#{emp.project.finName}" rendered="#{not empty emp.project.finName}" />
                            </rich:column>
                            <rich:column rendered="false">
                                <f:facet name="header">编号</f:facet>
                                <h:outputText value="#{emp.number}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">品目</f:facet>
                                <h:outputText value="#{emp.cate.name}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">计量单位</f:facet>
                                <h:outputText value="#{emp.cate.unit}"/>
                            </rich:column>
                            <rich:column style="width:60px;">
                                <f:facet name="header">采购数量</f:facet>
                                <h:outputText id="countId" value="#{emp.cate.count}"
                                              style="width:70px;">
                                    <f:convertNumber type="double" pattern="#,##0.00"/>
                                </h:outputText>
                                <h:message id="messageC" for="countId" style="color:red"/>
                            </rich:column>
                            <rich:column style="text-align: right;width:120px">
                                <f:facet name="header">财政性资金</f:facet>
                                <h:outputText id="financialId" value="#{emp.financial}">
                                    <f:convertNumber type="number" pattern="#,##0.00"/>
                                </h:outputText>
                                <h:message id="messageF" for="financialId" style="color:red"/>
                            </rich:column>
                            <rich:column style="text-align:right;width:120px">
                                <f:facet name="header">其他资金</f:facet>
                                <h:outputText id="otherId" value="#{emp.other}">
                                    <f:convertNumber type="number" pattern="#,##0.00"/>
                                </h:outputText>
                                <h:message id="messageO" for="otherId" style="color:red"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">组织形式</f:facet>
                                <h:outputText value="集中采购" rendered="#{emp.organizeForm == '0'}"/>
                                <h:outputText value="部门集中采购" rendered="#{emp.organizeForm == '1'}"/>
                                <h:outputText value="分散采购" rendered="#{emp.organizeForm == '2'}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">委托的集中采购机构</f:facet>
                                <h:outputText value="#{emp.organ}"/>
                            </rich:column>
                            <rich:column>
                                <f:facet name="header">采购方式</f:facet>
                                <h:outputText value="公开招标" rendered="#{emp.cateWay == '0'}"/>
                                <h:outputText value="邀请招标" rendered="#{emp.cateWay == '1'}"/>
                                <h:outputText value="竞争性谈判" rendered="#{emp.cateWay == '2'}"/>
                                <h:outputText value="单一来源" rendered="#{emp.cateWay == '3'}"/>
                                <h:outputText value="询价" rendered="#{emp.cateWay == '4'}"/>
                            </rich:column>
                            <f:facet name="footer"/>
                        </rich:dataTable>
                    </div>
                </h:panelGroup>                   
            </rich:panel>
        </h:form>
    </rich:popupPanel>

    <rich:popupPanel id="appendPanel" autosized="true" width="600" height="200">
        <f:facet name="header">资产信息</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('appendPanel')}.hide();
                                               return false;">关闭</h:outputLink>
        </f:facet>
        <h:form>
            <rich:panel>
                <h:panelGroup id="tableGroupa">        
                    <h:panelGrid id="editGridAppend" columns="4" width="100%" style="text-align:left;">
                        <h:outputLabel value="购入日期："/>
                        <h:panelGroup>
                            <rich:calendar value="#{buildAssetBean.exappend.date1}"
                                           locale="zh_CN"
                                           popup="true"
                                           datePattern="yyyy-MM-dd"
                                           showApplyButton="false"
                                           style="width:200px">
                            </rich:calendar>
                        </h:panelGroup>

                        <h:outputLabel value="资产名称："/>
                        <h:inputText value="#{buildAssetBean.exappend.content1}" />

                        <h:outputLabel value="品牌："/>
                        <h:inputText value="#{buildAssetBean.exappend.content2}"/>

                        <h:outputLabel value="厂商："/>
                        <h:inputText value="#{buildAssetBean.exappend.content3}"/>

                        <h:outputLabel value="规格型号："/>
                        <h:inputText value="#{buildAssetBean.exappend.content4}"/>                   
                    </h:panelGrid>                   
                </h:panelGroup>
                <a4j:commandButton value="确定" execute="tableGroupa" oncomplete="#{rich:component('appendPanel')}.hide()"/>
            </rich:panel>
        </h:form>
    </rich:popupPanel>

    <rich:popupPanel id="GBCodePlan" autosized="true" width="600" height="500">
        <f:facet name="header">国标码</f:facet>
        <f:facet name="controls">
            <h:outputLink value="#" onclick="#{rich:component('GBCodePlan')}.hide();
                                               return false;">关闭</h:outputLink>
        </f:facet>
        <h:form>
            <rich:panel id="EditGBCode">
                <a4j:commandButton value="确定" id="bt_GBCode"
                                   execute="@this" render="saveGroup"
                                   action="#{buildAssetBean.changeClassCode}"
                                   onclick="#{rich:component('GBCodePlan')}.hide();"
                                   disabled="#{empty buildAssetBean.node or buildAssetBean.node.isEnd eq 0}"/>

                <h:panelGroup id="GBCodeGroup">
                    <div style="height:400px;overflow:auto;">
                        <rich:tree value="#{assetGBCodeLazyLoadBean.rootNode}" var="idept"
                                   selectionType="ajax" toggleType="ajax"                                    
                                   toggleListener="#{assetGBCodeLazyLoadBean.toggleListener}"
                                   selectionChangeListener="#{buildAssetBean.selected}"
                                   style="width:300px"
                                   render="GBCodeGroup,bt_GBCode">
                            <rich:treeNode>
                                <h:outputText value="[#{idept.data.code}]#{idept.data.name}"/>
                            </rich:treeNode>
                        </rich:tree>
                    </div>
                </h:panelGroup>                   
            </rich:panel>
        </h:form>
    </rich:popupPanel>
</ui:composition>
